package finanz.kontrolle;

import android.app.Activity;
import android.content.Intent;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class MenuActivity extends Activity {

	public MenuActivity () {}
	
    public boolean onCreateOptionsMenu( Menu menu ) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate( R.menu.menugeral, menu );
		
		return true;
	}

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
           Intent i = new Intent( MenuActivity.this, HomeActivity.class );
           startActivity( i );
           finish();
        }
        return super.onKeyDown(keyCode, event);
    }
    
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent i = null;
		
		switch( item.getItemId() ) {
			case R.id.opcc1:
				i = new Intent( MenuActivity.this, BancoActivity.class );
			break;
			case R.id.opcc2:
				i = new Intent( MenuActivity.this, ContaActivity.class );
			break;
			case R.id.opcc3:
				i = new Intent( MenuActivity.this, CategoriaActivity.class );
			break;
			case R.id.opcc4:
				i = new Intent( MenuActivity.this, LancamentoActivity.class );
			break;
			case R.id.opcc5:
				Toast t = Toast.makeText( this, "Tenha um bom dia!", Toast.LENGTH_SHORT );
				t.setGravity( Gravity.CENTER, 0, 0 );
				t.show();
				
				finish();
	            System.exit(0);
				
			break;
		}
		
		if ( i != null )
			startActivity( i );
		
		return true;
	}
}